<?php defined("MAIN_DIR") or die("No direct access");

$limit = 10;
$page = UV::rInt(strip_tags($route->GET("page")));
if ($page < 1){
	$page = 1;
}

$query = "select SQL_CALC_FOUND_ROWS `U`.`id`,`U`.`login`,`U`.`type`,`U`.`last_time`
	from `users` as `U`
	order by `U`.`last_time`
    limit 100";
$list = $db->getTable($query);

$count = count($list);
$all_count = $db->getCell("SELECT FOUND_ROWS()");

require_once ADMIN.HEADFILE;
?>

<h1>Пользователи <a href='/admin/users/add/' class='button'>Добавить пользователя</a></h1>

<?php
if ($count){
	echo "<table class='statistics'>";
	echo "<tr><td class='c'>ID</td><td>Логин</td><td>Роль</td><td>Последняя активность</td><td>Действия</td></tr>";
	foreach ($list as $u) {
		echo "<tr>";
        echo "<td class='c'>".$u['id']."</td>";
		echo "<td>".$u['login']."</td>";
		echo "<td>".$u['type']."</td>";
		echo "<td>";
		echo date("j ", $u['last_time']);
		echo $srt_months[date("m", $u['last_time'])-1];
		echo date(" Y H:i", $u['last_time']);
		echo "</td>";
		echo "<td>";
			echo "<a class='action-edit' href='/admin/users/edit/{$u['id']}'><img src='/files/img/admin/edit.png' alt='Редактировать' title='Редактировать'></a> ";
			echo "<a class='action-trash' href='/admin/users/actions?action=trash&id[]={$u['id']}'><img src='/files/img/admin/trash.png' alt='Удалить' title='Удалить'></a>";
		echo "</td>";
		echo "</tr>";
	}
	echo "</table>";
}
echo showPages($all_count, $limit);

require_once ADMIN.FOOTERFILE; ?>